package com.lwt.db137.controller;

import com.lwt.db137.bean.Menu;
import com.lwt.db137.commen.R;
import com.lwt.db137.service.MenuService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lwt
 * @version 1.0
 * @Description
 * @date 2024/12/24 11:42
 */
@CrossOrigin(origins = "*")
@RestController
public class MenuController {
    @Autowired
    private MenuService menuService;
    //查看菜单
    @GetMapping("menuList")
    public R menuList(String label){
        return new R().addData("menuList",menuService.menuList(label));
    }
    //删除
    @GetMapping("deleteMenu")
    public int deleteMenu(@RequestParam("id") int id){
        return menuService.deleteById(id);
    }
    //添加
    @PostMapping("addMenu")
    public int addMenu(@RequestBody Menu menu){
        return menuService.insert(menu);
    }
    //修改
    @PostMapping("updateMenu")
    public int updateMenu(@RequestBody Menu menu){
        return menuService.updateMenuById(menu);
    }
    @GetMapping("menuTree")
    public R menuTree(String id){
        return new R().addData("menuById", menuService.getById(id));
    }
}
